/*
 * @Description: 密钥管理
 * @Author: franktrue 807615827@qq.com
 * @Date: 2021-08-02 08:08:10
 * @LastEditTime: 2021-08-02 08:39:11
 */
package model

import (
	"gorm.io/gorm"
)

type Auth struct {
	*Model
	AppKey    string `json:"app_key"`
	AppSecret string `json:"app_secret"`
}

func (auth Auth) TableName() string {
	return "blog_auth"
}

func (a Auth) Get(db *gorm.DB) (auth Auth, err error) {
	db = db.Where(
		"app_key = ? AND app_secret = ? AND deleted_at = 0",
		a.AppKey,
		a.AppSecret,
	)
	err = db.First(&auth).Error
	if err != nil && err != gorm.ErrRecordNotFound {
		return auth, err
	}
	return auth, nil
}
